<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-goods-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">商品条码：</label>
				<div class="col-sm-8">
					<input id="goodsBar" name="goodsBar" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">商品名称：</label>
				<div class="col-sm-8">
					<input id="goodsName" name="goodsName" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">规格：</label>
				<div class="col-sm-8">
					<input id="goodsSpec" name="goodsSpec" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属分类：</label>
				<div class="col-sm-8">
					<select name="gtypeId" id="type" class="form-control">

					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">供应商名称：</label>
				<div class="col-sm-8">
					<input id="supplier" name="supplier" class="form-control"
						type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">进货价格：</label>
				<div class="col-sm-8">
					<input id="bprice" name="bprice" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">销售价格：</label>
				<div class="col-sm-8">
					<input id="sprice" name="sprice" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">会员价：</label>
				<div class="col-sm-8">
					<input id="uprice" name="uprice" class="form-control" type="text">
				</div>
			</div>


		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "gxgw_modules/goods"
		$("#form-goods-add").validate({
			rules:{
				goodsBar:{
        			required:true,
        			minlength: 1,
        			maxlength: 256,
        			remote: {
                        url: ctx + "gxgw_modules/goods/checkGoodsBarUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#goodsBar").val());
                            }
                        },
                        dataFilter: function(data, type) {
                           
                        	return $.validate.unique(data);
                        }
                    }
        		},
				
				goodsName:{
        			required:true,
        			minlength: 1,
        			maxlength: 256,
        			remote: {
                        url: ctx + "gxgw_modules/goods/checkGoodsNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#goodsName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		
        		goodsSpec:{
            		required: true,

            		},
            		
            	supplier:{required: true, },
            	bprice:{
                	required: true,    //要求输入不能为空
                    number: true,     //输入必须是数字
                    min: 0.00,
                   //调用自定义验证
                    },	
                    
                sprice:{
                    required: true,
               	     number: true,     //输入必须是数字
                     min: 0.00,      //输入的数字最小值为0.01，不能为0或者负数 
                    },
                    
                uprice:{
                    required: true, 
                	 number: true,     //输入必须是数字
                     min: 0.00,      //输入的数字最小值为0.01，不能为0或者负数 
                      },	
                },
		messages: {
            "goodsName": {
                remote: "商品名称已经存在"
            },
            "goodsBar": {
                    remote: "商品条码已经存在"
                },
            "bprice": {
                remote:"请输入正确的金额格式"
           },
           "sprice": {
        	   remote:"请输入正确的金额格式"
           },
           "uprice": {
            	   remote:"请输入正确的金额格式"
                   },
           },
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-goods-add').serialize());
	        }
	    }
		 typeName();
         function typeName(){
         	$.ajax({
                 type: "post",
                 url:prefix + "/selectGtypeName",
                 dataType: "json",
                 success: function(res){
                     if (null != res) {
                         var html='';
                         Object.keys(res).forEach(function(key){
                             
                             html += '<option label="'+res[key].gtypeName+'" value="'+res[key].gtypeId+'"></option>'
                            
                         });
                         $('#type').html(html);
                         //必须加，刷新select
                     }}
              });
         }
        
           

	</script>
</body>
</html>
